# 读取多个文件
files_name = [r"datatest\pg100.txt",r"datatest\pg75268.txt"]

def count_words(filename):
    with open(filename,encoding='utf-8') as f:
        content = f.read()
        words = content.split()
        num_words = len(words)
    return num_words

for file_name in files_name:
    try:
        words_num = count_words(file_name)
    except FileNotFoundError:
        print(f"{file_name} is not found.")
    else:
        print(f"{file_name} has {words_num} words.")